#include <algorithm>
#include <cstdio>

const int N = 1000005, inf = 0x7fffffff;
int n, k, a[N], val[N << 2];
int OR, AND;

int query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return val[x];
  int mid, res;
  mid = (l + r) >> 1, res = inf;
  if (L <= mid) res &= query(x << 1, l, mid, L, R);
  if (mid < R) res &= query(x << 1 | 1, mid + 1, r, L, R);
  return res;
}

void build(int x, int l, int r) {
  if (l == r) return val[x] = a[l], void();
  int mid;
  mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  val[x] = val[x << 1] & val[x << 1 | 1];
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("sequence.in", "r", stdin);
  freopen("sequence.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    OR |= a[i];
  }
  build(1, 1, n);
  for (int i = 1; i <= n - k + 1; ++i) AND = std::max(AND, query(1, 1, n, i, i + k - 1));
  printf("%d %d", OR, AND);
  return 0;
}